<admintpl file="header" />
<script type="text/javascript" src="__PUBLIC__/js/jquery.cityselect.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/cropbox.js"></script>
<link href="__PUBLIC__/css/style.css"  rel="stylesheet" type="text/css">
</head>
<style>
    .input_edit{
        width:120px;
    }
</style>
<body>
<div class="wrap js-check-wrap">
    <div class="wrap js-check-wrap">
        <ul class="nav nav-tabs">
            <li <if condition="trim($_GET['a']) eq 'index'">class="active"</if>><a href="{:U('PeopleManagement/index', array('company_id'=>$company_id))}">员工列表</a></li>
            <li class="active"><a href="{:U('PeopleManagement/addPeople', array('company_id'=>$company_id))}">添加员工</a></li>
        </ul>
        <form method="post" class="form-horizontal js-ajax-form" action="{:U('PeopleManagement/addPeople', array('company_id'=>$company_id))}" >
            <div class="control-group">
                <label class="span1 control-label" style="width: 90px;"><span style="color: red;">*</span> 员工姓名：</label>
                <div class="span4">
                    <input type="text" name="people_name" >
                </div>
            </div>
            <div class="control-group">
                <label class="span1 control-label" style="width: 90px;"><span style="color: red;">*</span>员工照片：</label>
                <div class="container" style="margin-left:129px; ">
                    <div class="imageBox">
                        <div class="thumbBox"></div>
                        <div class="spinner" style="display: none">
                            <if condition="$people_info.cover_image neq ''">
                                <img id="imagePreview" src="{$people_info.cover_image}" style="width:150px;height: 140px;">
                                <input type="hidden" name="cover" id="cover" value="{$people_info.cover_image}">
                                <else/>Loading...
                            </if>
                        </div>
                    </div>
                    <div class="action">
                        <!-- <input type="file" id="file" style=" width: 200px">-->
                        <div class="new-contentarea tc"> <a href="javascript:void(0)" class="upload-img">
                            <label for="upload-file">上传图像</label>
                        </a>
                            <input type="file" class="" name="upload-file" id="upload-file" />
                        </div>
                        <input type="button" id="btnCrop"  class="Btnsty_peyton" value="裁切">
                        <input type="button" id="btnZoomIn" class="Btnsty_peyton" value="+"  >
                        <input type="button" id="btnZoomOut" class="Btnsty_peyton" value="-" >
                    </div>
                    <div class="cropped"></div>
                </div>
            </div>
            <!--<div class="control-group">-->
                <!--<label class="span1 control-label" style="width: 90px;"><span style="color: red;">*</span>员工照片：</label>-->
                <!--<div class="span4 wrapper">-->
                    <!--<div id="uploader-image">-->
                        <!--<div id="fileList" class="uploader-list">-->
                            <!--<div id="imageDiv" class="file-item thumbnail" style="width:150px;height: 150px;">-->
                                <!--<img id="imagePreview" src="__PUBLIC__/images/furley_bg.png" style="width:150px;height: 140px;">-->
                                <!--<div id="picker" class="info">选择图片&nbsp;&nbsp;&nbsp;&nbsp;</div>-->
                                <!--<input style="display:none;" type="file" id="imageFile" name="imageFile" >-->
                            <!--</div>-->
                        <!--</div>-->
                    <!--</div>-->
                <!--</div>-->
            <!--</div>-->

            <div class="control-group">
                <label class="span1 control-label" style="width: 90px;"><span style="color: red;">*</span> 员工邮箱：</label>
                <div class="span4">
                    <input type="text" name="email" >
                </div>
            </div>

            <div class="control-group">
                <label class="span1 control-label" style="width: 90px;"><span style="color: red;">*</span> 身份证号：</label>
                <div class="span4">
                    <input type="text" name="id_card" >
                </div>
            </div>

            <?php if($admin_type == 1 && !$company_id){ ?>
                <div class="control-group">
                    <label class="span1 control-label" style="width: 90px;"> 所在地区：</label>
                    <div id="city_1" class="span4">
                        <select class="prov" name="prov"></select>
                        <select class="city" name="city" id="city" disabled="disabled"></select>

                        <select class="company_name" name="company_id">
                            <foreach name="area_all_company" item="vo">
                                <option name="company" <?php if($head_company['company_id'] == $area_all_company['company_id']){echo 'selected="selected"';}?> value="{$vo.company_id}">{$vo.name}</option>
                            </foreach>
                        </select>

                    </div>
                </div>
            <?php }else{ ?>
                <input type="hidden" name="company_id" value="<?php echo I('company_id');?>">
            <?php } ?>

            <div class="form-actions" style="padding-left:260px;">
                <button type="submit" class="btn btn-primary js-ajax-submit" data-type="add">创建</button>
                &nbsp;&nbsp;<a class="btn" href="{:U('Company/index')}">{:L('BACK')}</a>
            </div>
        </form>
        <div class="pagination">{$page}</div>
    </div>

</div>
<script src="__PUBLIC__/js/common.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<script>
    function add_check(){
        var name = $("input[name='people_name']").val();
        var flag = false;
        $.ajax({
            type:"post",
            async:false,
            url:"{:U('Admin/Movement/filter_words')}",
            data:'name='+name,
            dataType:"text",
            success:function(data){
                if(data){
                    if(confirm('您编辑的内容涉及敏感词'+data+'是否继续操作')){
                        flag= true;
                    }else{
                        flag= false;
                    }
                }else{
                    flag = true;
                }
            }
        });
        return flag;
    }
    $(window).load(function() {
        var options =
        {
            thumbBox: '.thumbBox',
            spinner: '.spinner',
            imgSrc: 'images/avatar.png'
        }
        var cropper = $('.imageBox').cropbox(options);
        $('#upload-file').on('change', function(){
            var reader = new FileReader();
            reader.onload = function(e) {
                options.imgSrc = e.target.result;
                cropper = $('.imageBox').cropbox(options);
            }
            reader.readAsDataURL(this.files[0]);
            this.files = [];
        })
        $('#btnCrop').on('click', function(){
            var img = cropper.getDataURL();
            $('.cropped').html('');
            $('.cropped').append('<img src="'+img+'" align="absmiddle" style="width:180px;margin-top:4px;border-radius:180px;box-shadow:0px 0px 12px #7E7E7E;"><p>180px*180px</p><input type="hidden" value="'+img+'" name="photo">');
        })
        $('#btnZoomIn').on('click', function(){
            cropper.zoomIn();
        })
        $('#btnZoomOut').on('click', function(){
            cropper.zoomOut();
        })
    });

    $(function () {
        var prov = '{$head_company.prov}' ? '{$head_company.prov}' : '北京';
        var city = '{$head_company.city}' ? '{$head_company.city}' : '';
        $("#city_1").citySelect({
            url:"/public/js/city.js",
            prov: prov, //省份
            city: city, //城市
            nodata:"none" //当子集无数据时，隐藏select
        });

        //获取默认的公司
        /*var data = {city: ' 东城区  '};
        $.ajax({
            url: "{:U('PeopleManagement/getCompanyList')}",
            type: "POST",
            data: data,
            dataType: 'json',
            success: function (res) {
                var str = '';
                $('.company_name').children().remove();
                $.each(res, function (k, v) {
                    if(v.company_id){
                        str += '<option name="company" value="'+v.company_id+'">'+v.name+'</option>';
                    }
                })
                $('.company_name').append(str);
            },
            
            error: function () {
                alert('网络异常，请检查网络后重试');
            }
        });*/

        $('#city').bind('change', function () {
            var city = $(this).val();
            $.ajax({
                url: "{:U('PeopleManagement/getCompanyList')}",
                type: "POST",
                data: {city: city},
                dataType: 'json',
                success: function (res) {
                    var str = '';
                    $('.company_name').children().remove();
                    $.each(res, function (k, v) {
                        if(v.company_id){
                            str += '<option name="company" value="'+v.company_id+'">'+v.name+'</option>';
                        }
                    })
                    $('.company_name').append(str);
                },

                error: function () {
                    alert('网络异常，请检查网络后重试');
                }
            });
        })

        $('.prov').bind('change', function () {
            setTimeout(function () {
                var city = $('#city').val();
                if(!city){return false}
                $.ajax({
                    url: "{:U('PeopleManagement/getCompanyList')}",
                    type: "POST",
                    data: {city: city},
                    dataType: 'json',
                    success: function (res) {
                        var str = '';
                        $('.company_name').children().remove();
                        $.each(res, function (k, v) {
                            if(v.company_id){
                                str += '<option name="company" value="'+v.company_id+'">'+v.name+'</option>';
                            }
                        })
                        $('.company_name').append(str);
                    },

                    error: function () {
                        alert('网络异常，请检查网络后重试');
                    }
                });
            }, 50)
        })
    })

    function html5Reader(file, previewId){
        var file = file.files[0];
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function(e){
            $('#'+previewId).attr('src', this.result);
        }
    }
    function image_change(fileId, previewId) {
        var pic = document.getElementById(previewId),
            file = document.getElementById(fileId);

        var ext = file.value.substring(file.value.lastIndexOf(".")+1).toLowerCase();

        // gif在IE浏览器暂时无法显示
        if(ext != 'png' && ext != 'jpg' && ext != 'jpeg'){
            alert("图片的格式必须为png或者jpg或者jpeg格式！");
            return;
        }
        var isIE = navigator.userAgent.match(/MSIE/)!= null,
            isIE6 = navigator.userAgent.match(/MSIE 6.0/)!= null;

        if(isIE) {
            file.select();
            var realLocalPath = document.selection.createRange().text;

            // IE6浏览器设置img的src为本地路径可以直接显示图片
            if (isIE6) {
                pic.src = realLocalPath;
            }else {
                // 非IE6版本的IE由于安全问题直接设置img的src无法显示本地图片，但是可以通过滤镜来实现
                pic.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='image',src=\"" + realLocalPath + "\")";
                // 设置img的src为base64编码的透明图片 取消显示浏览器默认图片
                pic.src = '';
            }
        }else {
            html5Reader(file, previewId);
        }
    }

    $("#picker").click(function(){
        $("#imageFile").click();
    });

    $("#imageFile").change(function(){
        image_change('imageFile', 'imagePreview');
    });
</script>

</body>
</html>